Housing Rental Analysis for San Francisco

Import the data


Calculate and Plot the Housing Units per Year

Step 1: Use the groupby function to group the data by year. Aggregate the results by the mean of the groups.

Step 2: Use the hvplot function to plot the housing_units_by_year DataFrame as a bar chart. Make the x-axis represent the year and the y-axis represent the housing_units.

Step 3: Style and format the line plot to ensure a professionally styled visualization.

Step 5: Answer the following question:

Question: What is the overall trend in housing_units over the period being analyzed?

Answer: # steady increase of housing units over the years


Calculate and Plot the Average Sale Prices per Square Foot

Step 1: Group the data by year, and then average the results.

Question: What is the lowest gross rent reported for the years included in the DataFrame?

Answer: $ 1239

Step 2: Create a new DataFrame named prices_square_foot_by_year by filtering out the “housing_units” column. The new DataFrame should include the averages per year for only the sale price per square foot and the gross rent.

Step 3: Use hvPlot to plot the prices_square_foot_by_year DataFrame as a line plot.

Hint This single plot will include lines for both sale_price_sqr_foot and gross_rent

Step 4: Style and format the line plot to ensure a professionally styled visualization.

Step 6: Use both the prices_square_foot_by_year DataFrame and interactive plots to answer the following questions:

Question: Did any year experience a drop in the average sale price per square foot compared to the previous year?

Answer: # yes 2011 was lower than 2010

Question: If so, did the gross rent increase or decrease during that year?

Answer: # It had increased

---

Compare the Average Sale Prices by Neighborhood

Step 1: Create a new DataFrame that groups the original DataFrame by year and neighborhood. Aggregate the results by the mean of the groups.

Step 2: Filter out the “housing_units” column to create a DataFrame that includes only the sale_price_sqr_foot and gross_rent averages per year.

Step 3: Create an interactive line plot with hvPlot that visualizes both sale_price_sqr_foot and gross_rent. Set the x-axis parameter to the year (x="year"). Use the groupby parameter to create an interactive widget for neighborhood.

Step 4: Style and format the line plot to ensure a professionally styled visualization.

Step 6: Use the interactive visualization to answer the following question:

Question: For the Anza Vista neighborhood, is the average sale price per square foot for 2016 more or less than the price that’s listed for 2012?

Answer: # Less


Build an Interactive Neighborhood Map

Step 1: Read the neighborhood_coordinates.csv file from the Resources folder into the notebook, and create a DataFrame named neighborhood_locations_df. Be sure to set the index_col of the DataFrame as “Neighborhood”.

Step 2: Using the original sfo_data_df Dataframe, create a DataFrame named all_neighborhood_info_df that groups the data by neighborhood. Aggregate the results by the mean of the group.

Step 3: Review the two code cells that concatenate the neighborhood_locations_df DataFrame with the all_neighborhood_info_df DataFrame.

Note that the first cell uses the Pandas concat function to create a DataFrame named all_neighborhoods_df.

The second cell cleans the data and sets the “Neighborhood” column.

Be sure to run these cells to create the all_neighborhoods_df DataFrame, which you’ll need to create the geospatial visualization.

Step 4: Using hvPlot with GeoViews enabled, create a points plot for the all_neighborhoods_df DataFrame. Be sure to do the following:

Step 5: Use the interactive map to answer the following question:

Question: Which neighborhood has the highest gross rent, and which has the highest sale price per square foot?

Answer: # Westwood park has the highest gross rent, and union square has the highest sale price per square foot

Compose Your Data Story

Based on the visualizations that you have created, compose a data story that synthesizes your analysis by answering the following questions:

Question: How does the trend in rental income growth compare to the trend in sales prices? Does this same trend hold true for all the neighborhoods across San Francisco?

Answer: # They are positively correlated but this doesn't hold true for all of the neighborhoods.

Question: What insights can you share with your company about the potential one-click, buy-and-rent strategy that they're pursuing? Do neighborhoods exist that you would suggest for investment, and why?

Answer: # The strategy, looking at previous years data, would work well for most neighborhoods as rent rates have increased regardless of the sales price. This may be in an issue in some neighborhoods for if and when a client would want to exit and sell the property, but in theory this is a sound investment to hold.